﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace BloodBot
{
    public abstract class BaseState
    {
        public StateManager stateManager
        {
            get;
            set;
        }

        protected BasicEffect eff;

        protected Boolean isStateInitialized = false;
        protected Boolean isStateEnabled = false;

        protected BaseState(StateManager stateManager)
        {
            this.stateManager = stateManager;
        }

        public BaseState()
        {

        }

        public void Initialize()
        {
            LoadContent();

            isStateInitialized = true;
        }

        protected abstract void LoadContent();

        public abstract void Update(GameTime gameTime);

        public abstract void Draw(GameTime gameTime);


        protected Model LoadModel(string assetName, out Texture2D[] textures)
        {
            Model newModel = stateManager.Game.Content.Load<Model>(assetName);
            textures = new Texture2D[newModel.Meshes.Count];
            int i = 0;

            foreach (ModelMesh mesh in newModel.Meshes)
                foreach (BasicEffect currentEffect in mesh.Effects)
                    textures[i++] = currentEffect.Texture;

            foreach (ModelMesh mesh in newModel.Meshes)
                foreach (ModelMeshPart meshPart in mesh.MeshParts)
                    meshPart.Effect = eff.Clone();

            return newModel;
        }
    }
}
